import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class Servlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("ok1");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("dopost1");
        request.setCharacterEncoding("utf-8");//这是指定请求参数中中文提取解码方式
        response.setCharacterEncoding("utf-8");//指定响应消息体的中文编码方式
        response.setHeader("Content-Type","text/html;charset=utf-8");
        String cookie=request.getHeader("Cookie");
        String name=request.getParameter("xingming");
        String pwd=request.getParameter("mima");
        if(name.equals("张三")&&pwd.equals("123")){
//            response.getWriter().write("欢迎你，张三同学,登录成功！");
            response.sendRedirect("/welcome.html");
        }else{
            response.getWriter().write("用户名不存在，或者密码不正确，登录失败！,请重新登陆");
            response.setHeader("Refresh","3;URL=/form.html");
        }
    }
}
